/*
 * Beta.java
 *
 * Created on 16 de enero de 2002, 11:48 PM
 */

package InterfacesRiesgo;

/**
 *
 * @author  jfhenao
 */
import javax.swing.*;
public class Beta extends javax.swing.JDialog {
    
    private double B;
    private boolean seleccion;
    private static int numAlt;
    private int numEstNat;
    private double[] probabilidades;
    private double[][] matrizRiesgo;
    private String[] NombrEstNat;
    private static double[] ResulBeta=new double[numAlt];
    private String[] NombreAltern;
    private InterfacesDiscretas.PlataformaDiscreta Padre;
    private InterfacesGenerales.Plataforma Padre2;
    
    private InterfacesRiesgo.EstNaturaleza diferencia;
    
    public Beta(InterfacesDiscretas.PlataformaDiscreta parent,InterfacesGenerales.Plataforma parent2,boolean modal,InterfacesRiesgo.EstNaturaleza en, boolean seleccion) {
        super(parent2, modal);
        initComponents();
        jButton1.grabFocus();
        java.awt.Dimension nombre=java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setLocation(nombre.width/4-10,nombre.height/3);
        Padre=parent;
        Padre2=parent2;
        this.seleccion=seleccion;
        diferencia=en;
        numAlt=diferencia.getNumAlt();
        numEstNat=diferencia.getNumEstNat();
        NombreAltern=diferencia.getNombresAlter();
        NombrEstNat=diferencia.getNombresEstNat();
        matrizRiesgo=diferencia.getMatrizRiesgo();
        probabilidades=diferencia.getProbabilidades();
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    private void initComponents() {//GEN-BEGIN:initComponents
        java.awt.GridBagConstraints gridBagConstraints;

        jPanel1 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();

        setTitle("Criterio Beta Robustez");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        jPanel1.setLayout(new java.awt.BorderLayout());

        jPanel3.setBorder(new javax.swing.border.EtchedBorder());
        jButton1.setText("Aceptar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jPanel3.add(jButton1);

        jButton2.setText("Cancelar");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel3.add(jButton2);

        jPanel1.add(jPanel3, java.awt.BorderLayout.SOUTH);

        jPanel5.setLayout(new java.awt.GridBagLayout());

        jPanel5.setBorder(new javax.swing.border.EtchedBorder());
        jLabel1.setForeground(new java.awt.Color(0, 0, 153));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Defina para que porcentaje de logro considera");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        jPanel5.add(jLabel1, gridBagConstraints);

        jLabel2.setForeground(new java.awt.Color(0, 0, 153));
        jLabel2.setText(" las alternativas como aceptables (Beta)  : ");
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        jPanel5.add(jLabel2, gridBagConstraints);

        jTextField1.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        jTextField1.setText("80");
        jTextField1.setPreferredSize(new java.awt.Dimension(40, 21));
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        jPanel5.add(jTextField1, gridBagConstraints);

        jPanel1.add(jPanel5, java.awt.BorderLayout.CENTER);

        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);

        pack();
    }//GEN-END:initComponents
    
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        double[] resultOrden=new double[numAlt];
        String[] nombresOrden=new String[numAlt];
        boolean pasar=true;
        try{
            B=Double.parseDouble(jTextField1.getText())/100d;
        }catch(NumberFormatException e){
            pasar=false;
            jTextField1.setText("");
            jTextField1.grabFocus();
        }
        
        if(B>100 || B<0){
            JOptionPane.showMessageDialog(null,"El valor Beta debe estar entre 0 y 100","Advertencia",JOptionPane.WARNING_MESSAGE);
            pasar=false;
        }
        
        if(pasar==true){
            RiesgoDiscreto.Robustez.Beta run;
            run=new RiesgoDiscreto.Robustez.Beta(B,diferencia.getNumAlt(),diferencia.getNumEstNat(),diferencia.getMatrizRiesgo(),diferencia.getProbabilidades());
            ResulBeta=run.getBeta();
            
            resultOrden=Utiles.SacaMaximosMinimos.OrdenAscNumeros(ResulBeta,NombreAltern);
            nombresOrden=Utiles.SacaMaximosMinimos.OrdenAsc(ResulBeta,NombreAltern);
            
            for(int i=0;i<resultOrden.length;i++){
                resultOrden[i]=((int)(resultOrden[i]*100))/100d;
                ResulBeta[i]=((int)(ResulBeta[i]*100))/100d;
            }
            if(seleccion==true){
                Padre.metodoAddCriteriosRiesgo("Beta Robustez",ResulBeta);
                ResultadosDiscretos.Resultados objeto2= new ResultadosDiscretos.Resultados("Beta Robustez "+" (beta :"+jTextField1.getText()+" )","R[A]",numAlt,nombresOrden,nombresOrden,resultOrden,resultOrden,numEstNat,NombrEstNat,matrizRiesgo,probabilidades);
                Padre.getJDesktopPane2().add(objeto2);
            }
            
            setVisible(false);
            dispose();
        }
    }//GEN-LAST:event_jButton1ActionPerformed
    
    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        setVisible(false);
        dispose();
    }//GEN-LAST:event_jButton2ActionPerformed
    
    /** Closes the dialog */
    private void closeDialog(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_closeDialog
        setVisible(false);
        dispose();
    }//GEN-LAST:event_closeDialog
    private static double[] getBeta(){
        return ResulBeta;
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}